-- 
--  Stored Procedure: sp_TestConfiguration_save
--   Description: Inserts/Updates a TestConfiguration entry on the table
--   Parameters:
--     @name - host name
--     @cpu  - cpu vendor, model and cores
--     @ram  - ram amount
--     @os   - operating system
--   Return value: id of the created entry.
--
--  ATTENTION: the user defined function 'dbo.udf_TestConfiguration_find' should be created prior to this one.
-- 
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'sp_TestConfiguration_save')
  DROP PROCEDURE sp_TestConfiguration_save
GO
CREATE PROCEDURE sp_TestConfiguration_save
  @name nvarchar(30),
  @threads nvarchar(150),
  @cycle int,
  @samples int
AS
  -- if exists update values.
  IF (SELECT dbo.udf_TestConfiguration_find(@name)) IS NOT NULL
  BEGIN
    UPDATE TestConfiguration SET
      ThreadAmountList=@threads, Cycle=@cycle, Samples=@samples
      WHERE Name=@name
  END
  -- else, insert new test suite configuration.
  ELSE
  BEGIN	  
    INSERT INTO TestConfiguration 
	  (Name, ThreadAmountList, Cycle, Samples)
	  VALUES (@name, @threads, @cycle, @samples)
  END
GO
